<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./templates/templateMenu.xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="content">
        <script type="text/javascript"> //Reactualiza la tabla luego de eliminar pues necesitaria doble actualizacion
            function confirmFunction() {
                updateConfirm.jq.click();
            }
        </script>
        
        <p:panel header="Catalogo de Servicios">
            <h:panelGrid columns="3" id="frmCatalogo">
                <h:outputText value="Nombre Servicio: "/>
                <p:inputText id="txtServicio" 
                             value="#{catalogoBean.servicio.vcConceptoServicio}"
                             required="#{param['requireGroup1']=='1'}"/>
                <p:message for="txtServicio"/>

                <h:outputText value="Valor: "/>
                <p:spinner id="txtCosteServicio" 
                           value="#{catalogoBean.servicio.nuPrecioDefault}"
                           min="0"
                           stepFactor="0.01"
                           required="#{param['requireGroup1']=='1'}"/>
                <p:message for="txtCosteServicio"/>                
            </h:panelGrid>

            <h:panelGrid style="width: 100%">
                <p:toolbar>
                    <p:toolbarGroup align="left">      
                        <p:commandButton value="Nuevo" 
                                         title="Nuevo"
                                         action="#{catalogoBean.nuevo}"
                                         process="@this"
                                         update="frmCatalogo"
                                         image="ui-icon-document"/>
                        <p:commandButton value="Guardar"
                                         action="#{catalogoBean.crear}"
                                         process="@this frmCatalogo"
                                         oncomplete="confirmFunction();"
                                         update="frmCatalogo msg dtCatalogo"
                                         title="Guardar" 
                                         image="ui-icon-disk">
                            <f:param name="requireGroup1" value="1"/>
                        </p:commandButton> 
                    </p:toolbarGroup>
                </p:toolbar>
            </h:panelGrid>
            
            <p:dataTable id="dtCatalogo" 
                         widgetVar="dtCatalogo"                                        
                         rows="10" 
                         paginator="true" 
                         var="varCatalogo" 
                         value="#{catalogoBean.listaServicios}"
                         onRowEditUpdate="msg">

                <f:facet name="header">  
                    <h:panelGrid style="width: 200px;" 
                                 columnClasses="alignLeft,alignLeft,alignLeft" 
                                 columns="3">
                        <h:outputText value="Buscar: " />  
                        <p:inputText  id="globalFilter" 
                                      onkeyup="dtAnio.filter()" 
                                      style="width:150px" />  
                    </h:panelGrid> 
                </f:facet>  

                <p:column filterBy="#{varCatalogo.vcConceptoServicio}" filterStyle="display:none"
                          headerText="Concepto de Servicio" 
                          style="text-align: center;">
                    <h:outputText value="#{varCatalogo.vcConceptoServicio}"/>
                </p:column>

                <p:column filterBy="#{varCatalogo.nuPrecioDefault}" filterStyle="display:none"
                          headerText="Valor" 
                          style="text-align: center;"> 
                    <h:outputText value="#{varCatalogo.nuPrecioDefault}" />
                </p:column>   

                <p:column style="width: 75px; text-align: center; " headerText="Acciones" >  
                    <f:facet name="header"/>
                    <!-- <p:rowEditor/> ROWEDITOR PARA MODIFICAR -->
                    <p:commandButton  image="ui-icon-pencil" 
                                      title="Modificar Servicio"
                                      action="#{catalogoBean.modificar}"
                                      update="frmCatalogo"
                                      process="@this">  
                        <f:setPropertyActionListener value="#{varCatalogo}" target="#{catalogoBean.selectedServicio}" />
                    </p:commandButton>  
                    <p:commandButton  image="ui-icon-trash"
                                      title="Eliminar Servicio"
                                      oncomplete="confirmation.show()" 
                                      update="confirm" 
                                      process="@this">  
                        <f:setPropertyActionListener value="#{varCatalogo}" target="#{catalogoBean.selectedServicio}" />
                    </p:commandButton>  
                </p:column> 
            </p:dataTable>
        </p:panel>
        
        <p:confirmDialog message="Desea eliminar el registro?" 
                         width="400"   
                         header="Confirm" 
                         severity="alert" 
                         widgetVar="confirmation" 
                         modal="true">  
            <p:outputPanel id="confirm">
                <h:panelGrid>
                    <h:outputText  value="Servicio: #{catalogoBean.selectedServicio.vcConceptoServicio}"/>
                    <h:panelGrid columns="2">
                        <p:commandButton value="Si" 
                                         update="dtCatalogo frmCatalogo msg"
                                         action="#{catalogoBean.eliminar}" 
                                         oncomplete="confirmation.hide(); confirmFunction(); dtCatalogo.filter()" 
                                         process="@this">
                        </p:commandButton>
                        <p:commandButton value="No" 
                                         onclick="confirmation.hide()" 
                                         type="button" />    
                    </h:panelGrid>
                </h:panelGrid>
            </p:outputPanel>
        </p:confirmDialog>
        
        <p:commandButton style="visibility: hidden" 
                         widgetVar="updateConfirm"
                         oncomplete="dtCatalogo.filter()" 
                         update="dtCatalogo msg"/>
    </ui:define>

</ui:composition>
